home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MATH.SWG / 0010_PERMUTA1.PAS.pas < prev    next >
Pascal/Delphi Source File  |  1993-05-28  |  891b  |  39 lines

  1. {
  2. > Does anyone have an idea to perform permutations With pascal 7.0 ?
  3. > As an example finding the number of 5 card hands from a total of 52 cards.
  4. > Any help would be greatly appreciated.
  5.  
  6. This Program should work fine.  I tested it a few times and it seemed to work.
  7. It lets you call the Functions For permutation and combination just as you
  8. would Write them: P(n,r) and C(n,r).
  9. }
  10.  
  11. {$E+,N+}
  12. Program CombPerm;
  13.  
  14. Var
  15.   Result:Extended;
  16. Function Factorial(Num: Integer): Extended;
  17. Var
  18.   Counter: Integer;
  19.   Total: Extended;
  20. begin
  21.   Total:=1;
  22.   For Counter:=2 to Num do
  23.     Total:=Total * Counter;
  24.   Factorial:=Total;
  25. end;
  26.  
  27. Function P(N: Integer;  R: Integer): Extended;
  28. begin
  29.   P:=Factorial(N)/Factorial(N-R);
  30. end;
  31.  
  32. Function C(N: Integer;  R: Integer): Extended;
  33. begin
  34.   C:=Factorial(N)/(Factorial(N-R)*Factorial(R));
  35. end;
  36.  
  37. begin
  38.   Writeln(P(52,5));
  39. end.